GetSlaveById

Gets detailed information from a specified slave using an ID.

Syntax

KsError GetSlaveById(
     int SlaveId,
     SlaveStatus* Details
);

Parameters

SlaveId: the slave index. This index value is automatically assigned by the KINGSTAR master when the EtherCAT network starts, based on the physical connection order. The first device connected directly to the master is assigned Index 0, followed by Index 1, Index 2, and so on. These indexes remain consistent within the slave array even if devices are added, removed, or reconnected. Please refer to the use cases in HotConnect, Repair, and Restart for more details.

Details: pointer to the SlaveStatus structure that receives the detailed information about the slave's status.

Return value

If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.

Remarks

Retrieves details about a specified slave using the slave’s position in the EtherCAT loop. Since it uses the slave ID, it doesn't use the alias information. It works only for real slave modules without separating axes or I/Os. Use after the KINGSTAR Subsystem starts.

Usable EtherCAT states

ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP

Example

Copy
SlaveStatus slaveStatus = { 0 };
nRet = GetSlaveById(0, &slaveStatus);
if (nRet == errNoError)
{
    // Check the slave information in the SlaveStatus structure.
    RtPrintf("Device 0 %s: Vendor 0x%x, Product 0x%x, Revision 0x%x, Serial 0x%x\n",
             slaveStatus.Name, slaveStatus.VendorId, slaveStatus.ProductCode,
             slaveStatus.RevisionNumber, slaveStatus.SerialNumber);
    RtPrintf("Address: Auto %d, Fixed %d, Alias %d\n",
             slaveStatus.SlaveId, slaveStatus.PhysAddress, slaveStatus.AliasAddress);
    RtPrintf("PDO: Input len %d, Output len %d, Index offset 0x%x\n",
             slaveStatus.InputLength, slaveStatus.OutputLength, slaveStatus.VariableIndexOffset);
    RtPrintf("State %d, Cycle time %d\n", slaveStatus.State, slaveStatus.CycleTime);
}

Requirements

  RT Win32
Minimum supported version 4.0 4.0
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

GetIOByIndex

GetStatus

RequestSlaveState